<!DOCTYPE html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../common.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html lang="en">
    <head>        
    	<base href="<%=basePath%>">
        <!-- META SECTION -->
        <title>${htmlTitle}</title>            
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        
        <link rel="icon" href="favicon.ico" type="image/x-icon" />
        <!-- END META SECTION -->
    </head>
    <body>
    
    	<%@include file="../header.jsp"%>
    
        <!-- START PAGE CONTAINER -->
        <div class="page-container">
            
            <!-- START PAGE SIDEBAR -->
            	<%@include file="../left.jsp"%>
            <!-- END PAGE SIDEBAR -->
            
            <!-- PAGE CONTENT -->
            <div class="page-content">

                <!-- START BREADCRUMB -->
                <%=request.getAttribute("navigation") %> 
                <!-- END BREADCRUMB -->       
                
                <!-- START CONTENT FRAME -->
				<!-- END  CONTENT FRAME -->                
                
                <!-- PAGE CONTENT WRAPPER -->
                <div class="page-content-wrap">
					<div class="row">
						<div class="col-md-12" style="padding-top: 10px;">
							<form id="jvalidate" role="form" action="<%=basePath%>vehicle/saveOrUpdatePark" class="form-horizontal" method="post" enctype="multipart/form-data">
								<div class="panel panel-default">
									<div class="panel-body" style="border: none;">
									
										<input id="menuId" name="menuId" value="${currMenuId }" type="hidden" />
									
										<div class="form-group">
											<label class="col-md-3 col-xs-12 control-label">
												停车场名称
											</label>
											<div class="col-md-6 col-xs-12">
												<input id="id" name="id" value="${park.id }" type="hidden" />
												<input id="name" name="name" value="${park.name }" type="text" class="form-control" placeholder="请输入物业公司名称"/>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-md-3 col-xs-12 control-label">
												所属物业
											</label>
											<div class="col-md-6 col-xs-12">
												<select id="estateId" name="estateId" class=" form-control select"
													value="">
													<%=request.getAttribute("estateOptions")%>
												</select>
											</div>
										</div>
										
										<div class="form-group">
											<label class="col-md-3 col-xs-12 control-label">
												停车场类型
											</label>
											<div class="col-md-6 col-xs-12">
												<select id="type" name="type"
													class="form-control select">
													<option value="1"
														<c:if test="${park.type == 1 }" >selected="selected"</c:if>>
														室内停车场
													</option>
													<option value="2"
														<c:if test="${park.type == 2 }" >selected="selected"</c:if>>
														室外停车场
													</option>
												</select>
											</div>
										</div>
										
										<div class="form-group">
											<div class="col-md-3 ">
												<label class="col-md-12 control-label" style="margin-left: 10px;">
													免费时长
												</label>
											</div>
											<div class="col-md-2">
												<input id="freeTime" name="freeTime" type="text" class="form-control" value="${park.freeTime }" />
											</div>
											<div class="col-md-1">
												<label class="control-label" style="text-align: left; padding-left: 0px;">
													分
												</label>
											</div>
											<div class="col-md-1 ">
												<label class="control-label">
													滞留时间
												</label>
											</div>
											<div class="col-md-2">
												<input id="allowStayTime" name="allowStayTime" type="text" class="form-control" value="${park.allowStayTime }" />
											</div>
											<div class="col-md-1">
												<label class="control-label" style="text-align: left; padding-left: 0px;">
													分
												</label>
											</div>
										</div>
										
										
										<div class="form-group">
											<div class="col-md-3 ">
												<label class="col-md-12 col-xs-12 control-label"
													style="margin-left: 10px;">
													总车位数
												</label>
											</div>
											<div class="col-md-2">
												<input id="totalParkNum" name="totalParkNum" type="text"
													class="form-control" value="${park.totalParkNum }" />
											</div>
											<div class="col-md-1">
												<label class="control-label" style="text-align: left; padding-left: 0px;">
													个
												</label>
											</div>
											<div class="col-md-1 ">
												<label class="control-label">
													剩余车位
												</label>
											</div>
											<div class="col-md-2">
												<input id="remainParkNum" name="remainParkNum" type="text"
													class="form-control" value="${park.remainParkNum }" />
											</div>
											<div class="col-md-1">
												<label class="control-label" style="text-align: left; padding-left: 0px;">
													个
												</label>
											</div>
										</div>
										
										<div class="form-group">
											<div class="col-md-3">
												<label class="col-xs-12 control-label">
													价格
												</label>
											</div>
											<div class="col-md-2 col-xs-12">
												<input id="price" name="price" type="text" class="form-control" value="${park.price }" />
											</div>
											<div class="col-md-3">
												<label class="control-label" style="text-align: left; padding-left: 0px;">
													元/小时
												</label>
											</div>
										</div>
										
										<div class="form-group">
											<div class="col-md-3">
												<label class="col-xs-12 control-label">
													详细地址
												</label>
											</div>
											<div class="col-md-2 col-xs-12">
												<select id="city" name="city" class=" form-control select" value="" onchange="changeCity()">
<%-- 													<%=request.getAttribute("cityhtml")%> --%>
												</select>
											</div>
											<div class="col-md-2 col-xs-12">
												<select id="area" name="area" class=" form-control select" value="">
												</select>
											</div>
											<div class="col-md-2 col-xs-12">
												<input id="street" name="street" type="text"
													class="form-control" value="${park.street }" />
											</div>
										</div>
										
										<div class="form-group">
											<div class="col-md-3">
												<label class="col-xs-12 control-label">
													收费说明
												</label>
											</div>
											<div class="col-md-6 col-xs-12">
												<textarea class="form-control" rows="5" id="chargeDes" name="chargeDes">${park.chargeDes }</textarea>
											</div>
										</div>
										
									</div>
									<div class="panel-footer pull-center"
										style="text-align: center">
										<button class="btn btn-primary" type="button" onclick="back()">
											取消
										</button>
										<button class="btn btn-primary"  type="submit" >
											<c:if test="${isUpdate == 0}">
												确认新增
											</c:if>
											<c:if test="${isUpdate == 1}">
												确认修改
											</c:if>
										</button>
									</div>
								</div>
							</form>
						</div>
					</div>
                </div>
                <!-- END PAGE CONTENT WRAPPER -->                                
            </div>            
            <!-- END PAGE CONTENT -->
        </div>
        <!-- END PAGE CONTAINER -->
        
        <script type="text/javascript">
        
        	$(document).ready(function() {
        		validate();
        		init();
			});
        	
        	function validate() {
        		var jvalidate = $("#jvalidate").validate({
	                ignore: [],
	                rules: {                                            
	                        name: {
	                                required: true
	                        },
	                        freeTime: {
	                                required: true
	                        },
	                        allowStayTime: {
	                                required: true
	                        },
	                        totalParkNum: {
	                                required: true
	                        },
	                        remainParkNum: {
                                required: true
                        	},
                        	price: {
                                required: true
                        	},
                        	chargeDes: {
                        		required: true
                        	}
	                    }                                        
	                });
        	}
        	
        	function init() {
        		var message = '${message}';
        		var saveOk = '${saveOk}';
        		if (null != message && undefined != message && '' != message) {
        			$("#info").html(message);
 			   		$("#infoModal").modal("show");
        		}
        		if (saveOk=="1") {
        			setTimeout(function () {
     					back();
                    }, 2000);
        		}
        		initRegion();
        	}
        	
        	function initRegion() {
        		var city = '${park.city}';
        		var url = ctx + '/region/queryCityOptions';
				$.ajax(url, {
				    type: 'post',
				    data: {},
				    success: function(result){
				    	var rtn = JSON.parse(result);
				    	if (rtn.code==1) {
				    		$("#city").html(rtn.options);
					    	$('#city').selectpicker('refresh');
				    	} else {
				    		
				    	}
				    	
						if (city != '') {
							$("#city").val(city);
					    	$('#city').selectpicker('refresh');
						}
				    }
				});
				initArea(city);
        	}
        	
        	function changeCity() {
        		var city = $("#city").val();
        		initArea(city);
        	}
        	
        	function initArea(city) {
        		if(city != ''){
        			var area = '${park.area}';
					var url = ctx + '/region/queryAreaOptions';
					$.ajax(url, {
					    type: 'post',
					    data: {city:city},
					    success: function(result){
					    	var rtn = JSON.parse(result);
					    	if (rtn.code==1) {
					    		$("#area").html(rtn.options);
						    	$('#area').selectpicker('refresh');
					    	} else {
					    		
					    	}
					    	if (area != '') {
								$("#area").val(area);
						    	$('#area').selectpicker('refresh');
							}
					    }
					});
				}else{
					$("#area").html('<option value="">-请选择-</option>');
			    	$('#area').selectpicker('refresh');
				}
        	}
        	
        	function back(){
        		var menuId = '${currMenuId}';
	         	window.location = ctx +"/vehicle/parkList?menuId=" + menuId;
	        }
        </script>
    </body>
</html>